﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace SchoolTools
{
    /// <summary>
    /// FloatingBallWindow.xaml 的交互逻辑
    /// </summary>
    public partial class FloatingBallWindow : Window
    {
        private bool isFirstTime = false;
        public FloatingBallWindow()
        {
            InitializeComponent();
            // 判断是否第一次设置位置
            if (Properties.Settings.Default.BallLeft == 0 && Properties.Settings.Default.BallTop == 0)
            {
                // 首次启动，默认显示在屏幕右下角
                isFirstTime = true;
                this.Loaded += (s, e) => MoveToBottomRight();
            }
            else
            {
                // 从设置中恢复位置
                this.Left = Properties.Settings.Default.BallLeft;
                this.Top = Properties.Settings.Default.BallTop;
            }
        }
        // 实现窗口拖动（鼠标左键按下时拖动窗口）
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);
            this.DragMove();

            // 拖动结束后保存位置
            Properties.Settings.Default.BallLeft = this.Left;
            Properties.Settings.Default.BallTop = this.Top;
            Properties.Settings.Default.Save();
        }
        // 第一次显示，定位到右下角
        private void MoveToBottomRight()
        {
            var workingArea = SystemParameters.WorkArea;
            this.Left = workingArea.Right - this.Width - 10;
            this.Top = workingArea.Bottom - this.Height - 10;
        }
    }
}
